package com.example.rdl;

import com.example.rdl.generated.*;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.File;

public class App {
    public static void main(String[] args) throws Exception {
        JAXBContext context = JAXBContext.newInstance(Report.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();

        Report report = (Report) unmarshaller.unmarshal(
            new File("src/test/resources/sample-2005.rdl")
        );

        System.out.println("=== 成功解析 RDL 2005 报表 ===");
        System.out.println("报表名称: " + report.getName());

        if (report.getDataSets() != null) {
            for (DataSet ds : report.getDataSets().getDataSet()) {
                System.out.println("数据集: " + ds.getName());
                if (ds.getFields() != null) {
                    for (Field field : ds.getFields().getField()) {
                        System.out.println("  字段名: " + field.getName() +
                                         " | 映射字段: " + field.getDataField() +
                                         " | 数据类型: " + field.getTypeName());
                    }
                }
            }
        }

        if (report.getReportParameters() != null) {
            for (ReportParameter param : report.getReportParameters().getReportParameter()) {
                System.out.println("报表参数: " + param.getName());
            }
        }
    }
}